package router

import (
	"github.com/gin-gonic/gin"

	"shop-manager/internal/logic"
	"shop-manager/internal/vo"
)

// RegisterContract 注册合同相关路由
func RegisterContract(api *gin.RouterGroup,
	contractLogic *logic.ContractLogic,
	handleBizRsp func(ctx *gin.Context, rsp any, err error),
	handleBizListRsp func(ctx *gin.Context, rsp any, total int64, err error),
) {
	contract := api.Group("/contract")
	{
		contract.POST("/create", func(ctx *gin.Context) {
			var req vo.CreateContractReq
			if err := ctx.ShouldBindJSON(&req); err != nil {
				return
			}
			err := contractLogic.CreateContract(&req)
			handleBizRsp(ctx, nil, err)
		})

		contract.POST("/update", func(ctx *gin.Context) {
			var req vo.UpdateContractReq
			if err := ctx.ShouldBindJSON(&req); err != nil {
				return
			}
			err := contractLogic.UpdateContract(&req)
			handleBizRsp(ctx, nil, err)
		})

		contract.POST("/delete", func(ctx *gin.Context) {
			var req vo.DeleteContractReq
			if err := ctx.ShouldBindJSON(&req); err != nil {
				return
			}
			err := contractLogic.DeleteContract(&req)
			handleBizRsp(ctx, nil, err)
		})

		contract.POST("/detail", func(ctx *gin.Context) {
			var req vo.GetContractReq
			if err := ctx.ShouldBindJSON(&req); err != nil {
				return
			}
			rsp, err := contractLogic.GetContractDetail(&req)
			handleBizRsp(ctx, rsp, err)
		})

		contract.POST("/list", func(ctx *gin.Context) {
			var req vo.ListContractReq
			if err := ctx.ShouldBindJSON(&req); err != nil {
				handleBizRsp(ctx, nil, err)
				return
			}
			rsp, err := contractLogic.GetContractList(&req)
			if err != nil {
				handleBizRsp(ctx, nil, err)
				return
			}
			handleBizRsp(ctx, rsp, err)
		})
	}
}
